<?php
include('../class/user.php');
include('../class/dbmodifier.php');
include('../class/country.php');
include('../class/role.php');
include('../class/project.php');
include('../class/job.php');
include('../class/quark.php');
include('../class/ressourcetype.php');
include('../class/ressourceext.php');
include('../class/jobsolution.php');
include('../class/function.php');
include('../class/quarktransmitted.php');

//Retrieve the job the quark must come from
$jobid = $_GET['jid'];
//retrieve the user who will perform the quark
$uid = $_GET['uid'];

/*
RETRIEVE ALL THE QUARKS FOR THE SPECIFIED JOB WHICH HAVE NOT BEEN ATTEMPTED BY THE USER AND HASN'T A SOLUTION
IN ORDER OF THE MOST RESPONCE
*/

//retrieve all the quarks for the specific job that the user hasn't solved yet in order most responses
$quark = quark::getNextQuarkByUserIdAndByJobId($uid,$jobid);

if($quark == NULL){
	//user as tried every quark 
	$qn = quarktransmitted::getLastQuarkTransmittedByUserId($uid,$jobid);
	$quark = quark::getQuarkByJobIdAndNotQuarkId($qn->getQuark()->getId(),$jobid);
}

//get the ressource path
$imgPath = $quark->getPathToRessource();
$imgPath = "..//".$imgPath;
//GET ALL THE SOLUTION FOR THE SPECIFIC QUARK
$currentSolution = jobsolution::getJobSolutionByJobId($jobid);
//LOG THE TRANSMISSION OF THE QUARK
quarktransmitted::createQuarkTransmitted($uid,$quark->getId())
?>

<link rel="stylesheet" type="text/css" href="../css/quarkview.css" />
<form id="quarkTry" action="receive.php" method="post">
<input type="hidden" name="uid" value="<?php echo  $uid;?>" />
<input type="hidden" name="qid" value="<?php echo $quark->getId();?>" />
<div id="container">           
	<div id="quarkContainer">
    	<table>
        	<tr>
            	<td rowspan="2" id="quarkRessource" ><img src="<?php echo $imgPath;?>"/></td>
            	<td style="vertical-align:top; width:100%;">
                		<div id="quarkQuestion">
							<?php echo $quark->getJob()->getDescription();?>
                        </div>
                </td>
            </tr>
            <tr>    
                <td id="quarkSolution">
                	<?php while($row = $currentSolution->fetch_assoc()){
							$temp = new jobsolution($row['id'],$row['job_id'],$row['name'],$row['value']);
							echo "<input type=\"radio\" name=\"solution\" ".
							"value=\"".$temp->getId()."\"> ".$temp->getName()."<br>";	
					}?>
                </td>
             </tr>
             <tr>
             	<td>&nbsp;</td>
                <td id="quarkSubmit"><img onclick="javascript:document.getElementById('quarkTry').submit();"
                			 src="../images/submit-quark.png"></td>
         </table>
    </div>
    	<table>
        	<tr>
            	<!--<td><img src="../images/accept-quark.png"></td>
                <td style="text-align:right;"><img src="../images/next-quark.png"></td>-->
			</tr>
        </table>    
</div>
</form>

